﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExamAnalysis.Model;

namespace ExamAnalysis.Controls
{
    public partial class DropDownTeacherList : System.Web.UI.UserControl
    {
        public event EventHandler SelectedTeacherChanged; //添加事件句柄
        private int _SchoolID = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindTeacherList(_SchoolID);
            }
        }
        protected void TeacherList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (SelectedTeacherChanged != null)
            {
                SelectedTeacherChanged(this, new EventArgs()); //激活SelectedClassChanged事件   
            }
        }
        protected void BindTeacherList(int schoolID)
        {
            if (_SchoolID > 0)
            {
                using (ExamAnalysisDataContext db = new ExamAnalysisDataContext())
                {
                    TeacherList.DataSource = db.TeacherInfo.Where(p => p.SchoolID == schoolID).ToList();
                    TeacherList.DataTextField = "TeacherName";
                    TeacherList.DataValueField = "TeacherID";
                    TeacherList.DataBind();
                }
            }
        }

        #region

        public Unit Width
        {
            get
            {
                return TeacherList.Width;
            }
            set
            {
                TeacherList.Width = value;
            }
        }
        public int SchoolID
        {
            get
            {
                return Convert.ToInt32(_SchoolID);
            }
            set
            {
                _SchoolID = value;
                BindTeacherList(_SchoolID);
            }
        }
        public int TeacherID
        {
            get
            {
                return Convert.ToInt32(TeacherList.SelectedValue);
            }
            set
            {
                TeacherList.SelectedValue = value.ToString();
            }
        }

        #endregion
    }
}